package com.xoa.controller.performance.leaderAssessment;

import com.xoa.model.performance.leaderAssessment.ScoreFlowItemLeader;
import com.xoa.model.performance.leaderAssessment.ScoreFlowLeaderWithBLOBs;
import com.xoa.service.performance.leaderAssessment.ScoreFlowLeaderService;
import com.xoa.service.sms.SmsService;
import com.xoa.util.ToJson;
import com.xoa.util.common.StringUtils;
import com.xoa.util.common.wrapper.BaseWrapper;
import com.xoa.util.page.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/ScoreFlowLeader")
/**
 * 考核任务
 */
public class ScoreFlowLeaderController {
    @Autowired
    private ScoreFlowLeaderService scoreFlowService;

    @Autowired
    private SmsService smsService;


    //考核任务页面
    @RequestMapping("/scoreFlow")
    public String assessmentTask(){
        return "app/hr/leaderAssessment/leaderAssessmentTask";
    }

    //考核管理
    @RequestMapping("/assessmentTaskment")
    public String assessmentTaskment(){
        return "app/hr/leaderAssessment/leaderAssessmentTaskment";
    }
    //考核查询
    @RequestMapping("/assessmentQuery")
    public String assessmentQuery(){
        return "app/hr/leaderAssessment/leaderAssessmentQuery";
    }
    //考核新建
    @RequestMapping("/assessmentNewedit")
    public String assessmentNewedit(){
        return "app/hr/leaderAssessment/leaderAssessmentNewedit";
    }
    //考核查询详情
    @RequestMapping("/assessmentQueryDetail")
    public String assessmentQueryDetail(){
        return "app/hr/leaderAssessment/leaderAssessmentQueryDetail";
    }
    //考核统计页面
    @RequestMapping("/assessmentTaskStatistics")
    public String assessmentTaskStatistics(){
        return "app/hr/leaderAssessment/leaderAssessmentTaskStatistics";
    }

    //考核页面
    @RequestMapping("/kaoheList")
    public String kaoheList(HttpServletRequest request){
        String type = request.getParameter("type");
        if(!StringUtils.checkNull(type)){
            String flowId = request.getParameter("flowId");
            if(type.equals("1"))
                smsService.setRead(request,"/ScoreFlowLeader/kaoheList?flowId="+flowId+"&type=1");
        }
        return "app/hr/leaderAssessment/leaderKaoheList";
    }

    //新建考核页面
    @RequestMapping("/newTask")
    public String newTask(){
        return "app/hr/leaderAssessment/leaderNewTask";
    }

    @RequestMapping("/addScoreFlow")
    @ResponseBody
    public ToJson addScoreFlow(ScoreFlowLeaderWithBLOBs scoreFlow, HttpServletRequest request){
        return scoreFlowService.addScoreFlow(scoreFlow,request);
    }

    @RequestMapping("/delScoreFlow")
    @ResponseBody
    public ToJson delScoreFlow(Integer flowId){
        return scoreFlowService.delScoreFlow(flowId);
    }

    @RequestMapping("/modifyScoreFlow")
    @ResponseBody
    public ToJson modifyScoreFlow(ScoreFlowLeaderWithBLOBs scoreFlow){
        return scoreFlowService.modifyScoreFlow(scoreFlow);
    }

    @RequestMapping("/selAllScoreFlow")
    @ResponseBody
    public ToJson selAllScoreFlow(HttpServletRequest request,ScoreFlowLeaderWithBLOBs scoreFlow, @RequestParam(value = "page",required = false) Integer page,
                                  @RequestParam(value = "pageSize",required = false) Integer pageSize,
                                  @RequestParam(value="useFlag",required = false) Boolean useFlag,String flowFlag2,String ifAssessment){

        return scoreFlowService.selAllScoreFlow( request,scoreFlow,page,pageSize,useFlag,flowFlag2,ifAssessment);
    }


    @RequestMapping("/selectCycle")
    @ResponseBody
    public ToJson selectCycle(HttpServletRequest request, String type){
        return scoreFlowService.selectCycle(request,type);
    }

    @RequestMapping("/updateDept")
    @ResponseBody
    public ToJson updateDept(HttpServletRequest request, Integer flowId, Integer deptId, String userId){
        return scoreFlowService.updateDept(request,flowId,deptId,userId);
    }

    @RequestMapping("/kelong")
    @ResponseBody
    public ToJson kelong(Integer flowId){
        return scoreFlowService.kelong(flowId);
    }

    @RequestMapping("/selUserByUserId")
    @ResponseBody
    public ToJson selUserByUserId(String userId){
        return scoreFlowService.selUserByUserId(userId);
    }

    @RequestMapping("/stopNow")
    @ResponseBody
    public ToJson stopNow(HttpServletRequest request,Integer flowId,String flowFlag, String remind,String tuisong){
        return scoreFlowService.stopNow(request ,flowId,flowFlag,remind,tuisong);
    }

    //考核任务修改时使用
    @RequestMapping("/selScoreFlow")
    @ResponseBody
    public ToJson selScoreFlow(String flowId){
        return scoreFlowService.selScoreFlow(Integer.parseInt(flowId));
    }

    // 考核任务查询的查阅详情接口
    @RequestMapping("/selScoreFlowDetail")
    @ResponseBody
    public ToJson<ScoreFlowItemLeader> selScoreFlowDetail(Integer flowId, Integer groupId, PageParams pageParams){
        return scoreFlowService.selScoreFlowDetail(flowId,groupId,pageParams);
    }

    // 自评查询接口
    @ResponseBody
    @RequestMapping("/selScoreSelfData")
    public ToJson selScoreSelfData(HttpServletRequest request, PageParams pageParams,String scoreSelfFlag){
        return scoreFlowService.selScoreSelfData(request, pageParams,scoreSelfFlag);
    }

    @ResponseBody
    @RequestMapping("selMyFlows")
    public BaseWrapper selMyPapers(HttpServletRequest request, PageParams pageParams) {
        return scoreFlowService.selMyFlows(request, pageParams);
    }

    @ResponseBody
    @RequestMapping("selPaperDetail")
    public BaseWrapper selPaperDetail(HttpServletRequest request, Integer flowId){
        return scoreFlowService.selPaperDetail(request ,flowId);
    }

    @ResponseBody
    @RequestMapping("setFlowItem")
    public BaseWrapper setFlowItem(HttpServletRequest request,ScoreFlowItemLeader scoreFlowItem,String userScores,Integer status){
        return scoreFlowService.setFlowItem(request, scoreFlowItem, userScores, status);
    }

}
